define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'users/big/index' + location.search,
                    add_url: 'users/big/add',
                    edit_url: 'users/big/edit',
                    //del_url: 'users/big/del',
                    multi_url: 'users/big/multi',
                    import_url: 'users/big/import',
                    table: 'big',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: '',
                commonSearch: true,
                searchFormVisible: true,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('序号'), formatter: function(value, row, index){
                                return ++index;
                            },operate: false},
                        {field: 'code', title: __('合伙人编号'), operate: 'LIKE'},
                        {field: 'name', title: __('合伙人姓名'), operate: 'LIKE'},
                        {field: 'organization', title: __('机构'), operate: 'LIKE'},
                        //{field: 'grade', title: __('大客户等级'), operate: false,searchList: {"0":__('无'),"1":__('一级合伙人'),"2":__('二级合伙人'),"3":__('三级合伙人')},formatter: Table.api.formatter.status},
                        {field: 'phone', title: __('电话'), operate: 'LIKE'},
                        {field: 'predict', title: __('业绩总额'), operate: false},
                        {field: 'consumption', title: __('疗程消费金额'), operate: false},
                        {field: 'group', title: __('团队消费金额'), operate: false},
                        {field: 'can', title: __('可提现金额'), operate: false},
                        {field: 'already', title: __('已提现金额'), operate: false},
                        {field: 'bigs.name', title: __('上级合伙人姓名'), operate: 'LIKE'},
                        {field: 'url', title: __('图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'status', title: __("状态"), searchList: {"0":__('未发布'),"1":__('已发布')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'detail',
                                //extend: 'data-area=\'["100%", "100%"]\'',
                                text: __('邀请微信详情'),
                                //icon: 'fa fa-list',
                                classname: 'btn btn-primary btn-xs btn-detail btn-dialog',
                                url: 'users/bigs/index?big_id={id}'
                            },
                                {
                                    name: 'detail',
                                    extend: 'data-area=\'["55%", "70%"]\'',
                                    text: __('日志'),
                                    //icon: 'fa fa-list',
                                    classname: 'btn btn-success btn-xs btn-detail btn-dialog',
                                    url: 'users/bigss/index?big_id={id}'
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'test/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'test/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'test/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});